package controllers;

import java.util.Collections;
import java.util.Set;

import models.Establishment;
import models.FoodCourt;
import models.MenuSection;
import models.Owner;
import models.Telephone;
import play.data.Upload;
import play.mvc.Controller;

public class Section extends Controller {
	public static void list(long establishmentId) {
		Establishment establishment = Establishment.findById(establishmentId);
		Set<MenuSection> sections = Collections.emptySet();

		if (establishment.isRemoved() == false) {
			sections = establishment.getMenu().getSections();
		}
		render(establishment, sections);
	}

	public static void blank(long establishmentId) {
		render(establishmentId);
	}

	public static void show(long id, long establishmentId) {
		MenuSection section = MenuSection.findById(id);
		render(section, establishmentId);
	}

	public static void delete(long id, long establishmentId) {
		MenuSection section = MenuSection.findById(id);
		section.delete();
		list(establishmentId);
	}
	
	public static void create(Establishment establishment, MenuSection section) {
		establishment.getMenu().getSections().add(section);
		establishment.save();
		list(establishment.getId());
	}
	
	public static void save(Establishment establishment, MenuSection section) {
		section.save();
		list(establishment.getId());
	}
}
